home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / filevirus26alib.lha / examples / fvfind.c next >
C/C++ Source or Header  |  1993-03-30  |  3KB  |  110 lines

  1. /* ----------------------------------------------------------------
  2.  *
  3.  *  Project: Filevirus Library
  4.  *
  5.  *  Program: fvfind.c
  6.  *
  7.  *  Author : Bjorn Reese <breese@imada.ou.dk>
  8.  *
  9.  *  Short  : Example of a simple virus detector that uses unpack.library
  10.  *           Compile with "sc LINK fvfind.c"
  11.  *
  12.  * ---------------------------------------------------------------- */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <dos/doshunks.h>
  20. #include <dos/dostags.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23.  
  24. #include <libraries/unpack.h>
  25. #include <proto/unpack.h>
  26. #include <libraries/filevirus.h>
  27. #include <proto/filevirus.h>
  28.  
  29. extern struct Library *SysBase;
  30. struct FilevirusBase *FilevirusBase=NULL;
  31.  
  32. /* ---------------------------------------------------------------- */
  33.  
  34. __saveds __asm void Scanner(
  35.   register __a1 struct FilevirusNode *p,
  36.   register __a4 struct UnpackInfo *pu)
  37. {
  38.  
  39.   p->fv_Buffer    = pu->ui_DecrunchAdr;
  40.   p->fv_BufferLen = pu->ui_DecrunchLen;
  41.  
  42.   printf("File: '%s' ", (pu->ui_UseFilenamePointer ? pu->ui_LoadNamePoi : pu->ui_Filename));
  43.  
  44.   if ( !fvCheckFile(p, 0) ) {
  45.  
  46.     if (p->fv_FileInfection != NULL) {
  47.  
  48.       printf("*** virus '%s' found\n", (p->fv_FileInfection)->fi_VirusName);
  49.  
  50.     } else printf("clean\n");
  51.  
  52.   } else printf("error %d\n", p->fv_Status);
  53. }
  54.  
  55. /* ---------------------------------------------------------------- */
  56.  
  57. void UnpackScanner(struct FilevirusNode *p, char *fname)
  58. {
  59.   struct Library *UnpackBase=NULL;
  60.   struct UnpackInfo *pu;
  61.  
  62.   if ( UnpackBase = OpenLibrary("unpack.library", 39) ) {
  63.  
  64.     if ( pu = upAllocCInfo() ) {
  65.  
  66.       pu->ui_Filename = fname;
  67.       pu->ui_Path     = "TEMP:klejne/"; /* must be unique as all files here will be deleted */
  68.       pu->ui_Jump     = (void (*)(void *, void *))Scanner;
  69.       pu->ui_TrackJump= (void (*)(void *, void *))Scanner;
  70.       pu->ui_UserData = p;
  71.       pu->ui_Flag     = 1<<UFB_Delete;
  72.  
  73.       if ( upDetermineFile(pu, fname) ) {
  74.  
  75.         printf("Cruncher: %s\n", pu->ui_CruncherName);
  76.         upUnpack(pu);
  77.  
  78.       } else {
  79.  
  80.         if ( upLoadFile(pu) ) {
  81.           Scanner(p, pu);
  82.           upFreeFile(pu);
  83.         }
  84.       }
  85.       upFreeCInfo(pu);
  86.     }
  87.     CloseLibrary(UnpackBase);
  88.   }
  89. }
  90. /* ---------------------------------------------------------------- */
  91.  
  92. int main(int argc, char *argv[])
  93. {
  94.   struct FilevirusNode *p;
  95.  
  96.   if ( FilevirusBase = (struct FilevirusBase *)OpenLibrary("filevirus.library", 2) ) {
  97.  
  98.     if ( p = fvAllocNode() ) {
  99.  
  100.       UnpackScanner(p, argv[1]);
  101.       fvFreeNode(p);
  102.  
  103.     } else fprintf(stderr, "fvAllocNode() failed\n");
  104.  
  105.     CloseLibrary((struct Library *)FilevirusBase);
  106.  
  107.   } else fprintf(stderr, "Cannot open 'filevirus.library'\n");
  108.  
  109. }
  110.